package com.ym.controller.soso;

import com.github.pagehelper.PageInfo;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.soso.domain.entity.AppHealthPlateEntity;
import com.ym.soso.domain.param.AppHealthPlatePublishParam;
import com.ym.soso.domain.param.AppHealthPlateQueryParam;
import com.ym.soso.domain.param.AppHealthPlateUpdateParam;
import com.ym.soso.domain.vo.AppHealthPlateListPcVO;
import com.ym.soso.service.IAppHealthPlateSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import static com.ym.common.constant.ValidRule.Add;
import static com.ym.common.constant.ValidRule.Update;

/**
 * 健康科普Controller
 *
 * @author ym
 * @date 2020-08-24
 */
@Api(tags = "soso-健康科普")
@RestController
@Validated
@RequestMapping("/soso/plate")
public class AppHealthPlateController extends BaseController {

	@Autowired
	private IAppHealthPlateSV appHealthPlateSV;

	@ApiOperation("查询健康科普列表")
	@Log(dataBase = false, printBody = false, printQuery = true)
	@GetMapping("/list")
	public APIResponse<PageInfo<AppHealthPlateListPcVO>> list(@Valid AppHealthPlateQueryParam queryParam) {
		PageInfo<AppHealthPlateListPcVO> page = appHealthPlateSV.page(queryParam);
		return successData(page);
	}

	@ApiOperation("获取健康科普详细信息")
	@Log(dataBase = false, printBody = false, printQuery = true)
	@GetMapping(value = "/info")
	public APIResponse<AppHealthPlateEntity> info(@RequestParam Long id) {
		AppHealthPlateEntity data = appHealthPlateSV.selectById(id);
		return successData(data);
	}

	@ApiOperation("新增健康科普")
	@Log(printQuery = false)
	@PostMapping("/insert")
	public APIResponse insert(@RequestBody @Validated(value = Add.class) AppHealthPlateUpdateParam updateParam) {
		Long id = appHealthPlateSV.insertPC(updateParam);
		return successData(id);
	}

	@ApiOperation("修改健康科普")
	@Log(printQuery = false)
	@PostMapping("/update")
	public APIResponse update(@RequestBody @Validated(value = Update.class) AppHealthPlateUpdateParam updateParam) {
		int result = appHealthPlateSV.updateByIdPC(updateParam);
		return successData(result);
	}

	@ApiOperation("删除健康科普")
	@Log(printQuery = false)
	@PostMapping("/delete")
	public APIResponse delete(@RequestBody @Valid @NotNull Long[] ids) {
		int result = appHealthPlateSV.deleteByIds(ids);
		return successData(result);
	}

	@ApiOperation("发布")
	@PostMapping(value = "/release")
	public APIResponse healthRelease(
			@RequestBody @Valid AppHealthPlatePublishParam publishParams
	) {
		appHealthPlateSV.release(publishParams);
		return success();
	}
}
